<?php
namespace Service;

/**
 * APi数据返回
 */
class JsonService
{
    private static $SUCCESS_MSG  = 'ok';
    private static $SUCCESS_CODE = 0;
    private static $ERROR_CODE   = 400;

    public static function result($msg = '', $data = [], $count = 0, $code)
    {
        return json(compact('msg', 'data', 'code', 'count'));
    }

    public static function success($msg, $data = [], $count = 0)
    {
        if(empty($msg)) $msg = self::$SUCCESS_MSG;
        return self::result($msg, $data, $count, self::$SUCCESS_CODE);
    }

    public static function fail($msg, $data = [], $count = 0)
    {
        return self::result($msg, $data, $count, self::$ERROR_CODE);
    }
}